package cn.zzf.algs.note.exercise.fundamental;

import edu.princeton.cs.algs4.StdOut;
import org.junit.jupiter.api.Test;

/**
 * 双向队列 deque
 * @author GaoFeng
 * @date 2019/11/29 15:04
 */
public class Ex1_3_33 {

    @Test
    public void test() {
        Deque<String> deque = new Deque<>();

        int size = 10;
        StringBuilder sb = new StringBuilder();

        // 向前推入

        for (int i = 0; i < size; i++) {
            deque.pushLeft(sb.append((char) ((int) 'a' + i)).toString());
        }


        sb.delete(0, sb.length());
        for (int i = 0; i < size; i++) {
            deque.pushRight(sb.append((char) ((int) 'a' + i)).toString());
        }


        for (String str : deque) {
            StdOut.println(str);
        }

        // element
        StdOut.println("====pop====");

        for (int i = 0;i < size;i++) {
            StdOut.println(deque.popLeft());
            StdOut.println(deque.popRight());
        }

        StdOut.println(deque.popRight());
        StdOut.println(deque.popLeft());
        StdOut.println(deque.size());

        for (String str : deque) {
            StdOut.println(str);
        }

    }
}